<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>在线考试系统</title>
    <link rel="shortcut icon" th:href="@{/static/favicon.ico}" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <!--[if lt IE 8]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <link th:href="@{/static/css/style.css}" rel="stylesheet">
    <link th:href="@{/static/css/style-list.min.css?v=4.0.0}" rel="stylesheet">
    <link th:href="@{/static/css/bootstrap.min.css}" rel="stylesheet">
    <link th:href="@{/static/css/font-awesome.min.css}" rel="stylesheet">
    <link th:href="@{/static/css/bootstrap-table.css}" rel="stylesheet">
    <link th:href="@{/static/css/animate.min.css}" rel="stylesheet">
    <link th:href="@{/static/css/admin.css}" rel="stylesheet">
    <link th:href="@{/static/css/bootstrap-datetimepicker.min.css}" rel="stylesheet" />
    <link  th:href="@{/static/js/dist/jquery.validator.css}" rel="stylesheet" />
    <link th:href="@{/static/css/ui.css}" rel="stylesheet">
</head>
<body class="gray-bg">
<form id="form" class="form-horizontal" role="form" enctype="multipart/form-data"  th:method="post" th:action="@{../detail/submit}">
    <input type="hidden" name="id" id="id"/>
    <input type="hidden" name="paperId" th:value="${paperId}"/>
    <input type="hidden" name="paperType" th:value="${paperType}"/>
    <div class="form-group">
        <label class="control-label col-sm-3">章节类型</label>
        <div class="col-sm-7">
            <select class="form-control" name="sectionType"  id="sectionType" data-rule="required;" >
                <option value="">无</option>
            </select>
        </div>
    </div>
    <div class="form-group" style="display: none" id="questionNumBody">
        <label class="control-label col-sm-3">试题数量</label>
        <div class="col-sm-7">
            <input type="number" name="questionNum" id="questionNum" class="form-control" data-rule="required;" value="0"/>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-sm-3">试题分数</label>
        <div class="col-sm-7">
            <input type="number" name="questionScore" id="questionScore" class="form-control" data-rule="required;"/>
        </div>
    </div>
    <div class="form-group" style="display: none"  id="levelScaleBody">
        <label class="control-label col-sm-3">难度比例</label>
        <div class="col-sm-7">
            <table>
                <tr>
                   <td width="20%">
                       简单：<input type="number" size="4" name="levelScale" value="0"  class="form-control" data-rule="required;"/>
                   </td>
                    <td width="20%">
                        普通：<input type="number" size="4" name="levelScale" value="0" class="form-control" data-rule="required;" />
                    </td>
                    <td width="20%">
                        中等：<input type="number" size="4" name="levelScale" value="0"  class="form-control" data-rule="required;"/>
                    </td>
                    <td width="20%">
                        较难：<input type="number" size="4" name="levelScale" value="0" class="form-control" data-rule="required;" />
                    </td>
                    <td width="20%">
                        困难：<input type="number" size="4" name="levelScale" value="0"  class="form-control" data-rule="required;"/>
                    </td>
                </tr>
            </table>
           </div>
    </div>
    <div class="form-group" style="display: none"  id="qdbIdsBody">
        <label class="control-label col-sm-3">包含题库</label>
        <div class="col-sm-7">
            <input type="hidden" name="qdbIds" value="0" id="qdbIds"/>
            <input type="text" id="qdbNames"  class="form-control" />
        </div>
    </div>
    <div class="form-group" style="display: none" id="saveBody">
        <div class="col-sm-7 col-sm-offset-3">
            <button class="btn btn-primary" type="button" onclick="submitForm()">保存内容</button>
            <button class="btn btn-white" type="reset">取消</button>
        </div>
    </div>
</form>
<script th:src="@{/static/js/jquery-3.3.1.min.js}" type="text/javascript" charset="utf-8"></script>
<script th:src="@{/static/js/bootstrap.min.js}" type="text/javascript" charset="utf-8"></script>
<script th:src="@{/static/js/bootstrap-table.min.js}" type="text/javascript" charset="utf-8"></script>
<script th:src="@{/static/js/bootstrap-table-editable.min.js}" type="text/javascript" charset="utf-8"></script>
<script th:src="@{/static/js/bootstrap-table-zh-CN.min.js}" type="text/javascript" charset="utf-8"></script>
<script th:src="@{/static/js/layer/layer.js}" type="text/javascript" charset="utf-8"></script>
<script th:src="@{/static/js/bootstrap-editable.min.js}" type="text/javascript" charset="utf-8"></script>
<script  th:src="@{/static/js/bootstrap-datetimepicker.min.js}"></script>
<script  th:src="@{/static/js/bootstrap-datetimepicker.zh-CN.js}"></script>
<script  th:src="@{/static/js/dist/jquery.validator.min.js}"></script>
<script  th:src="@{/static/js/dist/local/zh-CN.js}"></script>
<script  th:inline="javascript">
    /*<![CDATA[*/
    var types = [[${types}]];
    for(var i=0;i<types.length;i++){
        var type=types[i];
        $('#sectionType').append("<option  value='"+type.id+"'>"+type.value+"</option>");
    }
    var paperType = [[${paperType}]];
    if(paperType==2){
        $("#questionNumBody").show();
        $("#levelScaleBody").show();
        $("#qdbIdsBody").show();
        $("#saveBody").show();
        var paperSectionVo=[[${paperSectionVo}]];
        if(paperSectionVo!=null){
            var levelScales = paperSectionVo.levelScales;
            var levelScaleInput = $("input[name='levelScale']");
            for (var i=0;i<levelScaleInput.length;i++){
                levelScaleInput.eq(i).val(levelScales[i]);
            }
            var qdbNames=[];
            var qdbIds=[]
            for (var i=0;i<paperSectionVo.qdbs.length;i++){
                qdbNames.push(paperSectionVo.qdbs[i].qdbName);
                qdbIds.push(paperSectionVo.qdbs[i].id);
            }
            $("#id").val(paperSectionVo.id);
            $("#questionNum").val(paperSectionVo.questionNum);
            $("#questionScore").val(paperSectionVo.questionScore);
            $("#qdbNames").val(qdbNames.length==0?'无':qdbNames.join(","));
            $("#qdbIds").val(qdbIds.join(","));
            $("#sectionType option[value='"+paperSectionVo.sectionTypeId+"']").attr("selected", true);
            $("#sectionType").attr("disabled",true);
        }
    }
    /*]]>*/
    function submitForm(){
        if(paperType==2){
            var qdbNames = $("#qdbNames").val();
            if(qdbNames==null||qdbNames==""){
                alert("请选择题库");
                return false;
            }
        }
        $("#sectionType").removeAttr("disabled");
        $("#form").submit();
    }
    $("#qdbNames").on("focus",function () {
        this.blur();
        layer.open({
            type:2,
            area:['780px','500px'],
            title: '修改',
            btn:['确定','取消'],
            content:'../qdb/list',
            yes:function(index,layero){
                var iframeName = layero.find("iframe")[0]['name'];
                var iframeWindow = window[iframeName];
                iframeWindow.submitForm();
            }
        });
    });
</script>
</body>
</html>